<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:fn="http://java.sun.com/jsp/jstl/functions"
	xmlns:p="http://primefaces.org/ui"
	xmlns:cc="http://java.sun.com/jsf/composite"
	xmlns:hmrDetail="http://java.sun.com/jsf/composite/detail"	>

<cc:interface>
	<cc:attribute name="handler"				type="com.hemerasolutions.v2trainer.component.interfaces.search.ModalitySearchCompInterface" required="true"/>
	<cc:attribute name="onSearchComplete"		type="java.lang.String" 	default="" 				required="false"/>
	<cc:attribute name="onCompleteSelect"		type="java.lang.String" 	default="" 				required="false"/>
	<cc:attribute name="searchUpdate"			type="java.lang.String" 	default="" 				required="false"/>
	<cc:attribute name="update"					type="java.lang.String" 	default=""				required="false"/>
	<cc:attribute name="showResultsPanel"		type="java.lang.Boolean"	default="false"			required="false"/>				
</cc:interface>

<cc:implementation>
	<span id="#{cc.clientId}" >
		<h:form id="formSearchModality" prependId="false">
			<h:panelGrid columns="2" cellpadding="2">

				<h:outputLabel 	value="#{msgs.ModalityName} :" />
				<p:inputText	value="#{ cc.attrs.handler.findByModalityName}" 	maxlength="20" 	size="20" />

				<h:outputLabel 	value="#{msgs.ModalityType} :" />
	            <p:selectCheckboxMenu id="modalityTypes" value="#{cc.attrs.handler.findByTrainingTypes}"  
	            	label="#{msgs.ModalityTypes}" filter="true" panelStyle="width:220px" converter="#{genericConverter }">
	            	<f:selectItems  value="#{cc.attrs.handler.trainingTypes}" var="trainingType" itemLabel="#{msgs[trainingType.name]}" itemValue="#{trainingType}"   />
	            </p:selectCheckboxMenu>

				<h:outputLabel 	value="#{msgs.Description} :" />
				<p:inputText	value="#{cc.attrs.handler.findByModalityDescription}" 	maxlength="50" 	size="40" />

				<h:outputLabel	value="#{ msgs.CreatedAt} :" />
				<h:column>
					<p:calendar		value="#{cc.attrs.handler.begCreatedAt}"		locale="pt"		timeZone="Brazil/East" selectOtherMonths="true" readOnlyInputText="true"  />
                      #{ msgs.To}
                     <p:calendar	value="#{cc.attrs.handler.endCreatedAt}"			locale="pt"		timeZone="Brazil/East" selectOtherMonths="true"	readOnlyInputText="true" />
				</h:column>

				<h:outputLabel	value="#{ msgs.ChangedAt} :" />
				<h:column>
					<p:calendar		value="#{cc.attrs.handler.begChangedAt}"		locale="pt"		timeZone="Brazil/East" selectOtherMonths="true" readOnlyInputText="true"  />
                      #{ msgs.To}
                   	<p:calendar		value="#{cc.attrs.handler.endChangedAt}"		locale="pt"		timeZone="Brazil/East" selectOtherMonths="true"	readOnlyInputText="true" />
				</h:column>
			</h:panelGrid>
			<p:commandButton value="#{ msgs.Search}"	actionListener="#{cc.attrs.handler.searchModality}"	icon=" ui-icon-search" 
				oncomplete="#{cc.attrs.onSearchComplete}"  process="@form" update=":growl formSearchModality #{cc.attrs.searchUpdate} #{cc.attrs.update}   " />
			<p:commandButton value="#{ msgs.Clear}"		type="button"	icon="ui-icon-clean" >
				 <p:ajax update="formSearchModality" resetValues="true" />  	
			</p:commandButton>
			
			<p:outputPanel id="resultPanel" rendered="#{not empty cc.attrs.handler.foundedVersionableModalitys and cc.attrs.showResultsPanel}">
				<c:if test="#{cc.attrs.showResultsPanel}">
					<p:spacer height="15"/>
					<p:dataTable id="modalitysTable" value="#{cc.attrs.handler.foundedVersionableModalitys}" var="versionableModality" paginator="true"  paginatorAlwaysVisible="false"  paginatorPosition="bottom" rows="15" emptyMessage="#{msgs.NoResults}">
						<p:columnGroup type="header">  
							<p:row>
								<p:column colspan="5">
									<f:facet name="header">
										<h:outputText value="#{msgs.Modalitys}" />
									</f:facet>
								</p:column>

							</p:row>
							<p:row>
								<p:column	colspan="3">
									<f:facet name="header">
										<h:outputText value="#{msgs.Name}"/>
									</f:facet>
								</p:column>
								<p:column	colspan="1" style="min-width:150px">
									<f:facet name="header">
										<h:outputText value="#{msgs.Description}"/>
									</f:facet>
								</p:column>

								<p:column style="max-width:15px"	colspan="1" >
									<f:facet name="header">
										<h:outputText value="#{msgs.Version}"/>
									</f:facet>
								</p:column>
		
							</p:row>	
						</p:columnGroup>
						<p:column colspan="1" styleClass="ui-widget-header ui-table-button-row"  > 
							<p:commandButton title="#{msgs.View}" action="#{cc.attrs.handler.toViewVersionableModality}" oncomplete="wmodalModalityView_#{cc.id}.show();"  
								icon="ui-icon-search"  styleClass="ui-table-button" update=":#{cc.clientId}:modalModalityView">
								<f:setPropertyActionListener target="#{cc.attrs.handler.versionableModality}" value="#{versionableModality}"/>
							</p:commandButton>
						</p:column>
						<p:column colspan="1"  >
							<h:outputText value="#{versionableModality.modality.name}" />
						</p:column>
						
						<p:column colspan="1" styleClass="ui-table-button-row">
							<p:commandButton title="#{msgs.Add}"  action="#{cc.attrs.handler.versionableModalitySelected}" icon="ui-icon-plus" styleClass="ui-table-button"
								update="#{cc.attrs.updateOnSelect}" oncomplete="#{cc.attrs.onCompleteSelect}">
								<f:setPropertyActionListener target="#{cc.attrs.handler.versionableModality}" value="#{versionableModality}"/>
							</p:commandButton>
						</p:column>							
												
						<p:column colspan="1"  >
							<h:outputText value="#{versionableModality.modality.description}" />
						</p:column>
						
						<p:column colspan="1" style="padding:1px;max-width:30px"  >
							<p:selectOneMenu value="#{versionableModality.modality}" converter="#{genericConverter}"  style="white-space: nowrap;width:100%"  
								panelStyle="max-width:30px;"	styleClass="ui-selector-on-table"  >
								<f:selectItems value="#{versionableModality.modalityVersions}" var="modalityVersion"  
									itemLabel="#{modalityVersion.version}" itemValue="#{modalityVersion}"/>
								<p:ajax  update="modalitysTable" />
							</p:selectOneMenu>
						</p:column>
					</p:dataTable>					
				</c:if>
			</p:outputPanel>	
		</h:form>
	</span>

	<c:if test="#{cc.attrs.showResultsPanel}">
		<p:dialog id="modalModalityView" header="#{msgs.Modality}: #{cc.attrs.handler.versionableModality.modality.name}" 
			appendTo="@(body)" modal="true" widgetVar="wmodalModalityView_#{cc.id}" >
			<hmrDetail:modalityDetails handler="#{cc.attrs.handler.modalityDetails}"/>
		</p:dialog>	

	</c:if>


</cc:implementation>
</html>	